package edu.bbu.cshu.wmpcWebGUI;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import edu.bbu.cshu.wmpc.plagiarism.PlagiarismTest;


/**
 * Servlet implementation class indexServlet
 */
@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	public void init(ServletConfig conf) throws ServletException{
		ServletContext sc = conf.getServletContext();
		String url = sc.getRealPath("/") + "WEB-INF/log4j.properties";
		url = url.replace("\\", "/");
		PlagiarismTest.INCTANCE.configureLogger(url);
		super.init(conf);
	}
	
    /**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 * Inicializalo fuggveny
	 * fileTypeList, testTypeList - a csatolt jarban milyen tipusu fileokat lehet hasonlitani, milyen tipusu algoritmusok vannak, hany fajta szint
	 * A Sessionbe bekerulnek az informaciok
	 * Sessionbe bekerelunke az informaciok
     * showCombos = 0 - ne jelenjen meg a fileokat tartalmazo Combo
	 * showResults = 0 - ne jelenjen meg az eredmeny, mivel meg nem volt teszt futtatva
	 * Main.jsp - betolti a fo megjelenito reszt
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
				
		ArrayList<String> fileTypesList = PlagiarismTest.INCTANCE.getFileTypes();
		ArrayList<String> testTypesList = PlagiarismTest.INCTANCE.getTestTypes();
		ArrayList<String> levelTypesList = PlagiarismTest.INCTANCE.getLevelTypes();
		ArrayList<String> ctp = new ArrayList<String>();
		ctp.add(testTypesList.get(0));
		
			
		HttpSession sess = request.getSession(true);
		sess.setAttribute("fFormat", fileTypesList.get(0));
		sess.setAttribute("lTypes", levelTypesList.get(0));
		sess.setAttribute("showCombos", 0);
		sess.setAttribute("showResults", 0);
		sess.setAttribute("fileTypesList", fileTypesList);
		sess.setAttribute("testTypesList", testTypesList);
		sess.setAttribute("cTypes",ctp); 
		sess.setAttribute("levelTypesList", levelTypesList);
		sess.setAttribute("Error", null);
		request.getRequestDispatcher("Main.jsp").forward(request, response);
	}

}
